home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / sets11.zip / Sets.TXT < prev    next >
Text File  |  1997-04-09  |  6KB  |  133 lines

  1.                                   Sets v. 1.1
  2.                                  by Hubert Chan
  3.  
  4. What it is
  5. ==========
  6.   It is a simple C++ class that allows you to create sets and use normal set
  7. operations on them, including union, intersection, etc.  It should work with
  8. any compiler that accepts the C++ 2.0 standard.
  9.   Included is a test program (SetTest.EXE), which is an OS/2 executable (the
  10. emx 0.8 runtime environment is required).  To run the program on an other
  11. system, you will have to recompile it.
  12.   The included makefile was made for emx 0.8 and dmake.  It can be modified to
  13. suit your compiler.
  14.  
  15. How to use it
  16. =============
  17.   You will have to modify Sets.HPP and recompile Sets.CPP to use it.  As it is,
  18. it will create a set that can contain the elements -3,-2,...,6.  To modify
  19. Sets.HPP, you just need to change MINELEMENT and MAXELEMENT to the smallest and
  20. largest possible values (respectively) that could be an element in a set.
  21.  
  22.   eg. if in a program, you want to use the elements -45,-44,...,19,20 in a set,
  23. then you would set MINELEMENT to -45, and MAXELEMENT to 20.
  24.  
  25.   These values are only used to conserve memory.  For example, if you want to
  26. have a set of numbers ranging from 300 - 350, you would have to use at least a
  27. 'short' type (ie. 2 bytes).  A set of 'short' values would take 65536 / 8 = 8192
  28. bytes, or 8 kb.  However, with MINELEMENT and MAXELEMENT set properly, it would
  29. only take 50 / 8 = 7 bytes < 1 kb, saving over kb of memory.  If you had a bunch
  30. of sets, the gain would be even greater.
  31.  
  32. NOTE: There is no range checking performed, so trying to add an element that is
  33. ----  out of range may produce interresting effects.
  34.  
  35.   If you want, you can also change Set::SetElement to some other type, as long
  36. as every element that you want to use is within the range of the type.  This is
  37. useful for saving memory, if, for example, you only have 5 elements in your
  38. set, and you don't want to use a whole 2 bytes (the size of in int on some
  39. systems) to refer to the elements.  Make sure that it is an ordinal type.
  40. Using a non-ordinal type (eg. float, double) may produce unexpected results.
  41.  
  42.   You will also have to include Sets.HPP in your source files if you want to
  43. use it.
  44.   There are a few ways to create a set.
  45.         Set S;                       creates S = { } = the empty set
  46.         Set S(2);                    creates S = { 2 }
  47.         Set::SetElement SElements[4] = { 3,5,7,1 };
  48.         Set S(4,SElements);          creates S = { 3,5,7,1 } = { 1,3,5,7 }
  49.           (The order of the numbers in SElements makes no difference.  The 4
  50.           in S(4,SElements) is the number of elements in the array SElements. )
  51.  
  52.   I have attempted to use the most logical operators for each set operation.  I
  53. also borrowed some operators from Turbo Pascal's set type.
  54.  
  55. The following table shows the operators and their meaning.  My home page has
  56. the same table, along with the meanings written in 'standard' mathematical
  57. notation (see below under 'Contacting me' for my home page).
  58.     operator(s) |   meaning
  59.    -------------+----------------------------------------
  60.         +,|     |  union of two sets
  61.        *,^,&    |  intersection of two sets
  62.     -(unary),~  |  complement (elements not in a set)
  63.      -(binary)  |  difference of two sets (or  S1 ^ ~S2)
  64.          <=     |  S1 is a subset of S2
  65.          <      |  S1 is a proper subset of S2
  66.          >=     |  S1 is a superset of S2
  67.          >      |  S1 is a proper superset of S2
  68.          ==     |  equivalence
  69.          !=     |  inequivalence
  70.  
  71.   >= can also be used to mean S1 contains element E.
  72.   <= can also be used to mean E is an element in S1
  73.  
  74. Disclaimer
  75. ==========
  76.   If you screw up your computer while using Sets, it's not my fault.
  77.  
  78. Contacting me
  79. =============
  80. e-mail: hyc@gpu.srv.ualberta.ca
  81.    or   hubert@cs.ualberta.ca (I don't check this one very often)
  82.  
  83. snail mail:
  84.   Hubert Chan
  85.   3 Falstaff Ave.
  86.   St. Albert, AB
  87.   Canada, T8N 1V3
  88.  
  89. WWW: http://www.ualberta.ca/~hyc/Programming/
  90.      this page should contain the latest version of Sets.
  91.  
  92. Cost
  93. ====
  94.   I'm not asking for any money from you if you want to use Sets.  On the other
  95. hand, I won't complain if you really want to send me something.
  96.   If you find Sets useful, please send me a note to let me know that someone is
  97. actualy using it.
  98.  
  99. New
  100. ===
  101. I would like to thank Darin McBride for his suggestions.  Some I have
  102. implemented, some will be implemented in future versions.
  103.  
  104. changes from version 1.0
  105. - now you can use 'E <= S' to mean 'E is an element of set S'.  As well, some
  106.   operators have been overloaded to accept elements as rvalues, instead of
  107.   converting them to sets first.
  108.  
  109. - now you set MINELEMENT and MAXELEMENT instead of MINELEMENT and NUMELEMENT.
  110.   NUMELEMENT is now calculated from MINELEMENT and MAXELEMENT.
  111.  
  112. - SetElement is now a public type in the Set class.
  113.  
  114. - There is now a << operator to concatenate a set with a string. (for doing
  115.   things like 'cout << "This is a set: " << S1;' )  Unfortunately, I don't have
  116.   the full C++ package on my computer, so I can't test it.  If you want to try
  117.   it out, it is at the bottom of the Sets.CPP file, commented out.  You will
  118.   also have to uncomment the line in Sets.HPP declaring '<<' as a friend.
  119.  
  120. - added a copy initializer Set(Set &).
  121.  
  122. To come - my plans for future versions
  123. =======
  124. in no particular order
  125. - make Sets a template to make it more versatile / easy to use
  126. - allow Sets to use user defined types.  Maybe allow sets of complex numbers,
  127.   polynomials, etc.  (OK, so this might be a bit too ambitious)
  128. - make MINELEMENT and MAXELEMENT local in the Set class (instead of making them
  129.   '#define'd constants).  Shouldn't be too hard to do, but my compiler just
  130.   won't accept it for some reason.
  131. - any suggestions you have
  132.  
  133.